//
//  SampuxUserTextFiledView.m
//  Sampux
//
//  Created by rzm on 16/7/5.
//  Copyright © 2016年 rzm. All rights reserved.
//

#import "SampuxCustomTextFiledView.h"

@interface SampuxCustomTextFiledView ()

@property (nonatomic, copy) NSString *rightImage;

@end

@implementation SampuxCustomTextFiledView

static  NSInteger count = 0;

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
    }
    return self;
}

- (void)createUserTextFiledWithPlaceholder:(NSString *)placeholder andLeftImage:(NSString *)leftImg andRightImage:(NSString *)rightImg;
{
    UIView *backView = [[UIView alloc]initWithFrame:self.bounds];
    [self addSubview:backView];
    self.rightImage = rightImg;

    _deleteBtn = [UIButton createButton];
    _deleteBtn.frame = CGRectMake(backView.width - 30, 0, 30, self.height);
    [backView addSubview:_deleteBtn];
    [_deleteBtn setImage:imageNamed(rightImg) forState:UIControlStateNormal];
    [_deleteBtn setImage:imageNamed(@"eye_selected") forState:UIControlStateSelected];

    [_deleteBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    _deleteBtn.hitTestEdgeInsets = UIEdgeInsetsMake(- 10, -20, -10, -20);

    _textFiled = [UITextField createTextFieldWithRect:CGRectMake(0, 0,  _deleteBtn.x - 5, backView.height) andPlaceholder:placeholder andLeftImage:leftImg];

    [backView addSubview:_textFiled];
    [UIView createLineViewInbottom:backView];
}



- (void)btnClick:(UIButton *)btn
{
//    if ([self.rightImage isEqualToString:@"delete"]) {
//        self.textFiled.text = @"";
//    }else
//    {
    btn.selected = !btn.selected;

    if (btn.selected) {
          self.textFiled.secureTextEntry = NO;
//        [btn setImage:imageNamed(@"eye_selected") forState:UIControlStateNormal];
    }else
    {
        self.textFiled.secureTextEntry = YES;
//        [btn setImage:imageNamed(@"eye") forState:UIControlStateNormal];
    }
//    }
}
@end
